package com.hhd.pdf;

import com.alibaba.fastjson.JSONObject;
import com.hhd.pdf.utils.PdfUtils;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

@Getter
@Builder
@Setter
public class GeneratorParameters {
    private String outputPath;
    private String configPath;
    private JSONObject renderData;
    private int initPageWidth;
    private int initPageHeight;
    private int pageWidth;
    private int pageHeight;
    private BaseColor color;
    private BaseColor borderColor;
    private Font font;
    private int pagePaddingTop;
    private int pagePaddingBottom;
    private int pagePaddingLeft;
    private int pagePaddingRight;
    private String formType;
    private int align = Paragraph.ALIGN_LEFT;

    public GeneratorParameters init() {
        initPageWidth = 900;
        initPageHeight = 10000;
        pageWidth = 900;
        pageHeight = 500;
        pagePaddingTop = 30;
        pagePaddingBottom = 0;
        pagePaddingLeft = 30;
        pagePaddingRight = 30;
        align = Paragraph.ALIGN_LEFT;

        color = new BaseColor(89, 89, 89);
        borderColor = new BaseColor(233, 233, 233);
        try {
            font = PdfUtils.createFont(10, color);
            font.setStyle(Font.NORMAL);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return this;
    }

    public GeneratorParameters clone() {
        GeneratorParameters res = GeneratorParameters.builder().build();
        BeanUtils.copyProperties(this, res);
        return res;
    }
}
